package com.youpai.platform.chat.service.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.youpai.platform.chat.service.constant.ChatConstants;
import com.youpai.platform.chat.service.converter.ChatAccountConverter;
import com.youpai.platform.chat.service.entity.dto.ChatAccountDTO;
import com.youpai.platform.chat.service.entity.po.ChatAccountPO;
import com.youpai.platform.chat.service.mapper.ChatAccountMapper;
import com.youpai.platform.chat.service.service.ChatAccountService;
import com.youpai.platform.chat.service.util.ChatUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @date: 2022/7/11 11:15
 * @author: Anna
 * @version: 1.0
 * @description: 账户service
 */
@Slf4j
@Component
public class ChatChatAccountServiceImpl implements ChatAccountService {

    @Resource
    private ChatAccountMapper chatAccountMapper;

    @Override
    public void createAccount(ChatAccountDTO chatAccountDTO) {
        ChatAccountPO chatAccountPO = ChatAccountConverter.convertChatAccountDTO2ChatAccountPO(chatAccountDTO);
        chatAccountPO.setAccId(ChatUtils.buildAccId(chatAccountDTO.getAppId(), chatAccountDTO.getUid()));
        log.info("createAccount - {}", JSONObject.toJSONString(chatAccountPO));
        chatAccountMapper.insert(chatAccountPO);
    }

    @Override
    public Long getSystemUid() {
        return ChatConstants.SYSTEM_COUNT_ACC_ID;
    }
}
